package com.hsp.poly_.objpoly;

public class ToString_ {
    public static void main(String[] args) {
        //getClass().getName()  类的全类名（包名+类名）
        /*
        Integer.toHexString(hashCode())  将对象的hashCode值转成16进制字符串
        public String toString(){
            return getClass() + "@" + Integer.toHexString(hashCode());
         */
        Monster monster = new Monster("小妖怪","巡山",1000);
        System.out.println(monster.toString()+"   hashcode="+monster.hashCode());
        System.out.println(monster);
    }
}

class Monster{
    private String name;
    private String job;
    private double salary;

    public Monster(String name, String job, double salary) {
        this.name = name;
        this.job = job;
        this.salary = salary;
    }
    //重写toString方法，输出对象的属性
    //使用快捷键

    @Override
    public String toString() {
        return "Monster{" +
                "name='" + name + '\'' +
                ", job='" + job + '\'' +
                ", salary=" + salary +
                '}';
    }
}

